package com.lagou.concurrent.demo;

import java.util.concurrent.*;

public class Main2 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCallable myCallable = new MyCallable();

        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                5, 5,
                1, TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10)
        ) {
            //方法执行完成后执行这里
            @Override
            protected void afterExecute(Runnable r, Throwable t) {
                // 如果在call方法执行过程中有错误，则可以在此处进行处理
//                super.afterExecute(r, t);
                System.out.println("任务执行完毕Runnable值" + r);
                System.out.println("任务执行完毕Callable值" + t);
            }
        };


        Future<String> future = executor.submit(myCallable);

        String result = future.get();
        System.out.println(result);

        executor.shutdown();
    }
}
